/// <reference path="jquery-1.8.2.min.js" />
/// <reference path="jquery-easyui-1.3.2/easyloader.js" />
easyloader.locale = "zh_CN"; 
easyloader.css = false; 
$(function () {
    
    $.each($(".tabspanel"), function (i, n) {
        $(this).children(".tabscontentpanel").children(".tabcontent").hide().first().show();
        $(this).children(".customtabs").find("li").click(function () {
            $(this).siblings(".selected").removeClass("selected");
            $(this).addClass("selected");
            $(this).closest(".tabspanel").children(".tabscontentpanel").children(".tabcontent").hide().eq($(this).closest("li").index()).show();
        }).first().addClass("selected");
    });
    

    $("#btngjsearch").click(function () { 
        var _height = $("#advancedsearchdiv").height();
        if (_height <= 0) {
            $("#advancedsearchdiv").animate({ height: "65px", "padding-top": "10px", "border-top-width": "1px" }, 200);
        }
        else {
            $("#advancedsearchdiv").animate({ height: "0px", "padding-top": "0px", "border-top-width": "0px" }, 200);
        }
    });

    easyloader.load(['combobox', 'dialog', 'datagrid', 'menu'], function () { 
        $(".myeasyui-combobox").combobox();
        
        $("#funcicondiv .btnicon.btncol").click(function (e) {
            var $this = $(this);
            if ($("#btncolmenu").length <= 0) { /*the menu obj has bean created*/
                var smenu = $('<div style="width:100px;" id="btncolmenu"></div>').appendTo('body');
                var fields = $("#sdatatab").datagrid('getColumnFields');
                for (var i = 0; i < fields.length; i++) {
                    var fildOption = $("#sdatatab").datagrid('getColumnOption', fields[i]);
                    if (!fildOption.hidden) {
                        $('<div iconCls="icon-ok" field="' + fields[i] + '"/>').html(fildOption.title).appendTo(smenu);
                    } else {
                        $('<div iconCls="icon-empty" field="' + fields[i] + '"/>').html(fildOption.title).appendTo(smenu);
                    }
                }
                smenu.menu({
                    onClick: function (item) {
                        var field = $(item.target).attr('field');
                        if (item.iconCls == 'icon-ok') {
                            $("#sdatatab").datagrid('hideColumn', field);
                            $(this).menu('setIcon', {
                                target: item.target,
                                iconCls: 'icon-empty'
                            });
                        } else {
                            $("#sdatatab").datagrid('showColumn', field);
                            $(this).menu('setIcon', {
                                target: item.target,
                                iconCls: 'icon-ok'
                            });
                        }
                    }
                });
            }
            $("#btncolmenu").menu("show", {
                left: $this.offset().left,
                top: $this.offset().top + $this.height()
            });
        });
    });
    
     $(window).resize(function () {
     	$("#sdatatab").datagrid('resize', {
            width: $("#datatabdiv").width()
    	});
    });
});

function formatterdata(value, row, index) {
    var datalength = 10;
    if (value && value.length > 10) {
        return value.substring(0, datalength) + "...";
    }
    return value;
}
